<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Beijing Alcatel-Lucent Bus</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />    
    <!-- Combo-handled YUI CSS files: -->
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.6.0/build/reset-fonts-grids/reset-fonts-grids.css&2.6.0/build/button/assets/skins/sam/button.css&2.6.0/build/datatable/assets/skins/sam/datatable.css">
    <!-- Combo-handled YUI JS files: -->
    <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&2.6.0/build/element/element-beta-min.js&2.6.0/build/button/button-min.js&2.6.0/build/connection/connection-min.js&2.6.0/build/datasource/datasource-min.js&2.6.0/build/datatable/datatable-min.js&2.6.0/build/json/json-min.js"></script>


    <style type="text/css" rel="stylesheet">
    .mapStyle
    { 
           border-top:1px solid #999;
           border-right:1px solid #999;
           border-bottom:1px solid #999;
           border-left:1px solid #999;
           height: 520px;
    }
    .delete-button {
        cursor: pointer;
        background: transparent url(static_dir/delete_icon.png) no-repeat center center;
        width: 14px;  height: 14px;
    }
    .add-button {
        cursor: pointer;
        background: transparent url(static_dir/add_icon.png) no-repeat center center;
        width: 16px;  height: 16px;
    }
    .up-button {
        cursor: pointer;
        background: transparent url(static_dir/up_icon.gif) no-repeat center center;
        width: 11px;  height: 11px;
    } 
    .down-button {
        cursor: pointer;
        background: transparent url(static_dir/down_icon.gif) no-repeat center center;
        width: 11px;  height: 11px;
    }    
    </style>    
</head>
<body class=" yui-skin-sam">
<div id="doc3" class="yui-t7">
    <div id="hd">
        <div class="yui-gf">
            <div class="yui-u first">
                <a href="/bjlucentbus/"><img src="static_dir/logo.jpg" border="0"></a>
            </div>
            <div class="yui-u">
                <div class="yui-t4">
                    <div id="yui-main">
                        <div class="yui-b">
                            <span style="font-size: 138.5%">Beijing Alcatel-Lucent Bus</span>
                            <span style="font-size: 77%">(author: A.TNG)</span><br>
                            <span style="font-size: 77%">contact: tang.jiyu at gmail dot com / ji_yu.tang at lucent-alcatel dot com</span>
                        </div>
                    </div>
                    <div class="yui-b">
                        <ul>
                        <li><a href="static_dir/history.html" target="_blank">更新历史</a></li>
                        <li><a href="http://tinyurl.com/58rhwa" target="_blank">班车地图1.0 RC Q&A</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="bd">
    <div class="yui-gf">
    <div class="yui-u first">
    <!-- YOUR DATA GOES HERE -->
        <table width="100%" border="1" align="center" valign="top" cellpadding="0" cellspacing="0" bgcolor="#f8f8f8" style="border:1px solid #e1e1e1;" >
          <tr>
            <td width="100%">
              编辑 <b>{{ banche.linenum }}</b> 班车
            </td>
          </tr>
          <tr>
            <td width="100%">--------</td>
          </tr>
          <tr>
            <td width="100%"><a href="/bjlucentbus/line?line={{banche.key}}">返回当前班车线路图</a></td>
          </tr>
          <tr>
            <td width="100%">--------</td>
          </tr>
        </table>
    </div>
    <div class="yui-u">
    <div id="editline"></div>
<script type="text/javascript">
data = {{json}};
YAHOO.util.Event.addListener(window, "load", function(){
    var col_def = [
        //{key:'id'},
        {key:'busstop', label:'站点名称', editor:new YAHOO.widget.TextboxCellEditor({
            disableBtns:true,
            asyncSubmitter: function (callback, newValue) {
                // console.log('in asyncsubmitter');
                banche_key = this.getRecord().getData('key');
                YAHOO.util.Connect.asyncRequest(
                    'POST',
                    'updatezhandian',
                    {
                        success: function(o) {
                            if (o.responseText != 'ERROR') {
                                callback(true, o.responseText);
                            } else {
                                alert(o.responseText);
                                callback();
                            }
                        },
                        failure: function(o) {
                            alert(o.statusText);
                            callback();
                        },
                        argument:[]
                    },
                    'banche_key='+banche_key+'&zhandianmingcheng='+newValue
                );
            }
        })},
        {key:'morningtime', label:'早班时间', editor:new YAHOO.widget.TextboxCellEditor({
            disableBtns:true,
            asyncSubmitter: function (callback, newValue) {
                banche_key = this.getRecord().getData('key');
                YAHOO.util.Connect.asyncRequest(
                    'POST',
                    'updatezhandian',
                    {
                        success: function(o) {
                            if (o.responseText != 'ERROR') {
                                callback(true, o.responseText);
                            } else {
                                alert(o.responseText);
                                callback()
                            }
                        },
                        failure: function(o) {
                            alert(o.statusText)
                            callback();
                        },
                        argument:[]
                    },
                    'banche_key='+banche_key+'&zaobanshijian='+newValue
                );
            }
        })},
        {key:'morning', label:'早班站点', editor:new YAHOO.widget.RadioCellEditor({
            radioOptions:['Yes', 'No'], 
            disableBtns:true,
            asyncSubmitter: function (callback, newValue) {
                banche_key = this.getRecord().getData('key');
                YAHOO.util.Connect.asyncRequest(
                    'POST',
                    'updatezhandian',
                    {
                        success: function(o) {
                            if (o.responseText != 'ERROR') {
                                callback(true, o.responseText);
                            } else {
                                alert(o.responseText);
                                callback()
                            }
                        },
                        failure: function(o) {
                            alert(o.statusText)
                            callback();
                        },
                        argument:[]
                    },
                    'banche_key='+banche_key+'&zaoban='+newValue
                );
            }
        })},
        {key:'night', label:'晚班站点', editor:new YAHOO.widget.RadioCellEditor({
            radioOptions:['Yes', 'No'], 
            disableBtns:true,
            asyncSubmitter: function (callback, newValue) {
                banche_key = this.getRecord().getData('key');
                YAHOO.util.Connect.asyncRequest(
                    'POST',
                    'updatezhandian',
                    {
                        success: function(o) {
                            if (o.responseText != 'ERROR') {
                                callback(true, o.responseText);
                            } else {
                                alert(o.responseText);
                                callback()
                            }
                        },
                        failure: function(o) {
                            alert(o.statusText)
                            callback();
                        },
                        argument:[]
                    },
                    'banche_key='+banche_key+'&wanban='+newValue
                );
            }            
        })},
        {key:'note', label:'备注', editor:new YAHOO.widget.TextboxCellEditor({
            disableBtns:true,
            asyncSubmitter: function (callback, newValue) {
                banche_key = this.getRecord().getData('key');
                YAHOO.util.Connect.asyncRequest(
                    'POST',
                    'updatezhandian',
                    {
                        success: function(o) {
                            if (o.responseText != 'ERROR') {
                                callback(true, o.responseText);
                            } else {
                                alert(o.responseText);
                                callback()
                            }
                        },
                        failure: function(o) {
                            alert(o.statusText)
                            callback();
                        },
                        argument:[]
                    },
                    'banche_key='+banche_key+'&beizhu='+newValue
                );
            }
        })},
        //{key:'key', label:'关键字'},
        {key:'up', label:'往上', className:'up-button'},
        {key:'down', label:'往下', className:'down-button'},
        {key:'add', label:'添加', className:'add-button'},
        {key:'delete', label:'删除', className:'delete-button'},
    ];
    var ds = new YAHOO.util.DataSource(data);
    ds.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
    ds.responseSchema = {
        fiedls:['busstop', 'morningtime', 'morning', 'night', 'key','note']
    };
    var dt = new YAHOO.widget.DataTable('editline', col_def, ds);

    dt.subscribe('cellMouseoverEvent', function(oArgs) {
        var elCell = oArgs.target;
        if (YAHOO.util.Dom.hasClass(elCell, 'yui-dt-editable')) {
            this.highlightCell(elCell);
        }
    });
    dt.subscribe('cellMouseoutEvent', dt.onEventUnhighlightCell);
    dt.subscribe('cellClickEvent', function(oArgs) {
        var elCell = oArgs.target;
        var column = dt.getColumn(elCell);
        switch(column.key) {
            case 'delete':
                if (confirm('Are you sure?')) {
                    //dt.deleteRow(elCell);
                    var record = dt.getRecord(elCell);
                    current_key = record.getData('key');
                    YAHOO.util.Connect.asyncRequest(
                        'GET',
                        'deletezhandian?banche_key={{ banche.key }}&zhandian_key='+current_key,
                        {
                            success:function(o) {
                                if (o.responseText == 'OK') {
                                    dt.deleteRow(elCell);
                                } else {
                                    alert(o.responseText);
                                }
                            },
                            failure:function(o) {
                                alert(o.statusText);
                            },
                            argument: []
                        }
                    );
                }
                break;
            case 'add':
                if(confirm('Are you sure?')) {
                    var record = dt.getRecord(elCell);
                    current_key = record.getData('key');
                    //console.log(current_key);
                    YAHOO.util.Connect.asyncRequest(
                        'GET',
                        'addzhandian?banche_key={{ banche.key }}&zhandian_key='+current_key,
                        {
                            success: function(o) {
                                if (o.responseText != 'ERROR') {
                                    //console.log(o.responseText);
                                    try {
                                        obj = YAHOO.lang.JSON.parse(o.responseText);
                                    } catch (x) {
                                        alert('JSON parse failed');
                                        return;
                                    }
                                    dt.addRow(obj, dt.getRecordIndex(elCell));
                                } else {
                                    alert('ERROR');
                                }
                            },
                            failure: function(o) {
                                alert(o.statusText);
                            },
                            argument:[]
                        }
                    );
                }
                //dt.addRow({}, dt.getRecordIndex(elCell))
                break;
            case 'up': 
                record = dt.getRecord(elCell);
                record_idx = dt.getRecordIndex(elCell);
                if (record_idx != 0) {
                    // 当前record不是最上面的纪录，则上移是允许的
                    YAHOO.util.Connect.asyncRequest(
                        'GET',
                        'updownzhandian?action=up&banche_key={{ banche.key }}&zhandian_key='+record.getData('key'),
                        {
                            success: function (o) {
                                if (o.responseText == 'OK') {
                                    // 上移record
                                    dt.deleteRow(elCell);
                                    // console.log(record._oData);
                                    dt.addRow(record._oData, record_idx-1);
                                } else {
                                    alert(o.responseText);
                                }
                            },
                            failure: function (o) {
                                alert(o.statusText);
                            },
                            argument:[]
                        }
                    );
                }
                break;
            case 'down':
                record = dt.getRecord(elCell);
                record_idx = dt.getRecordIndex(elCell);
                rec_total_num = dt.getRecordSet().getLength();
                if (rec_total_num-1 != record_idx) {
                    YAHOO.util.Connect.asyncRequest(
                        'GET',
                        'updownzhandian?action=down&banche_key={{ banche.key }}&zhandian_key='+record.getData('key'),
                        {
                            success: function(o) {
                                if (o.responseText == 'OK') {
                                    // 下移recrod
                                    dt.deleteRow(elCell);
                                    dt.addRow(record._oData, record_idx+1);
                                } else {
                                    alert(o.responseText);
                                }
                            },
                            failure: function(o) {
                                alert(o.statusText);
                            },
                            argument:[]
                        }
                    );
                }
                break;
            default:
                dt.onEventShowCellEditor(oArgs);
                break;
        }
    });
    
    /* init button event
    var btnAddBusStop = new YAHOO.widget.Button('addrow');
    btnAddBusStop.on('click', function(e) {
        alert('click');
    });*/
});
</script>    
    </div>
</div>
    </div>
    <div id="ft">
    </div>
</body>
</html>
